package de.hszigr.inf.webapp.common;

import java.util.List;
import java.util.Vector;

import org.apache.click.extras.control.Menu;
import org.apache.click.extras.control.MenuFactory;
import org.apache.click.util.Bindable;

import de.hszigr.inf.model.User;
import de.hszigr.inf.webapp.Login;

public class BorderTemplate extends org.apache.click.Page {
	
	@Bindable public String title = "Titel";
	@Bindable public String username;
	@Bindable protected Menu rootMenu;

	
	public User currentUser;
	
	public BorderTemplate() {
		rootMenu = new MenuFactory().getRootMenu();
		rootMenu.removeStyleClass("ul");
		
	}
	
	   public String getTemplate() {
		      return "/common/borderTemplate.htm";
		   }
	   
	@Override
	public void onGet() {
		currentUser = (User)getContext().getSessionAttribute("currentUser");
		if(currentUser == null){
			setRedirect(Login.class);
		}
		else{
			username = currentUser.getUsername();
			setRole(currentUser.getRole());
		}
	}

	public void setRole(String role){
		List<String> roles = new Vector<String>();
		roles.add(role);
		rootMenu.setRoles(roles);
	}
	

	
}